// pages/auth/index.js
import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import {login} from "../../utils/asyncWx";
Page({
//  获取用户信息
 async handleGetUserInfo(e){
  // console.log(e);
  try {
  const {encryptedData, rawData, iv, signature}=e.detail;
      const {code}= await login();
      const loginParams= {encryptedData, rawData, iv, signature,code}
  // console.log(code);
// 3 发送请求 获取token值
   const token = await request ({url:"/users/wxlogin",data:loginParams,method:"post"});
  // console.log(res);

  // 4 把token 存入缓存中，同时跳转回上一个页面
  wx.setStorageSync("token", 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo');
    // console.log(token);
  wx.navigateBack({
    delta: 1
  }); 
  
   } catch (error) {
     console.log(error);
   }
}
})